package com.fenghongzhang.day006anim;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private Button btn;
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn = (Button) findViewById(R.id.btn);
        img = (ImageView) findViewById(R.id.img);

    }

    public void alpha(View view) {
        //透明度
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
//        img.startAnimation(animation);

//        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
//        alphaAnimation.setDuration(2000);
//        alphaAnimation.setInterpolator(new LinearInterpolator());
//        btn.startAnimation(alphaAnimation);


        //移动
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.tran);
//        img.startAnimation(animation);

//        TranslateAnimation translateAnimation = new TranslateAnimation(0, 100, 0, 100);
//        translateAnimation.setDuration(2000);
//        translateAnimation.setFillAfter(true);
//        translateAnimation.setRepeatCount(1); //2
//        translateAnimation.setRepeatMode(Animation.REVERSE);
//        translateAnimation.setInterpolator(new LinearInterpolator());
//        btn.startAnimation(translateAnimation);


        //缩放
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);
////        btn.startAnimation(animation);
//
//        ScaleAnimation scaleAnimation = new ScaleAnimation(1, 2, 1, 2, 50, 50);
//        scaleAnimation.setDuration(2000);
//        scaleAnimation.setFillAfter(true);
//        scaleAnimation.setRepeatCount(1); //2
//        scaleAnimation.setRepeatMode(Animation.REVERSE);
//        scaleAnimation.setInterpolator(new LinearInterpolator());
//        btn.startAnimation(scaleAnimation);


        //旋转
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
//        btn.startAnimation(animation);
//        RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 0, 0);
//        rotateAnimation.setDuration(2000);
//        rotateAnimation.setFillAfter(true);
//        rotateAnimation.setRepeatCount(1); //2
//        rotateAnimation.setRepeatMode(Animation.REVERSE);
//        rotateAnimation.setInterpolator(new BounceInterpolator());
//        btn.startAnimation(rotateAnimation);


        //zuhe
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.set);
//        btn.startAnimation(animation);

//        AnimationSet animationSet = new AnimationSet(true);
//
//        animationSet.setDuration(2000);
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
//        Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.scale);
//        animationSet.addAnimation(animation);
//        animationSet.addAnimation(animation1);
//
//        btn.startAnimation(animationSet);


        img.setImageResource(R.drawable.git);
        AnimationDrawable drawable = (AnimationDrawable) img.getDrawable();
        drawable.start();


    }
}
